home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1996 June
/
MACPOWER-1996-06.ISO.7z
/
MACPOWER-1996-06.ISO
/
MacPowerオリジナル
/
SILICON MAGIC
/
リスト
/
リスト2
next >
Wrap
Text File
|
1996-04-12
|
5KB
|
137 lines
リスト2 Text2Tableの核心部分
CLEAR LOCAL
DIM aRect.8
DIM rowspanMk(_maxRow,_maxCol),rowspan(_maxRow,_maxCol)
DIM colspanMk(_maxRow,_maxCol),colspan(_maxRow,_maxCol)
LOCAL FN DoText2Table(fname$,vRefNum)
OPEN "I",1,fname$,,vRefNum 'Open text file for input
'Step 1 -- Find span marks ( = and " ) and build 2d span mark array
row=0
WHILE NOT (EOF(1) OR row>_maxRow)
INC(row):frstChr=_true
LINE INPUT #1, txt$ 'Read one line at a time
col=1
FOR c=1 TO LEN(txt$)
c$=MID$(txt$,c,1)
LONG IF c$=CHR$(34) AND frstChr 'ASCII 34 is double quote
rowspanMk(row,col)=_true 'If = or " is only char
XELSE 'in a cell, it is a span
LONG IF c$="=" AND frstChr 'mark. Multiple chars are
colspanMk(row,col)=_true 'never treat as a span mark
XELSE
LONG IF c$=CHR$(9)
INC(col)
frstChr=_true
XELSE
rowspanMk(row,col)=_false
colspanMk(row,col)=_false
frstChr=_false
END IF
END IF
END IF
NEXT
WEND
RECORD #1,0 'Reset file pointer for Step 3
lastRow=row:lastCol=col 'Get last numbers for Step 2
'Step 2 -- Build cell span arrays
FOR row=1 TO lastRow
FOR col=1 TO lastCol
co=col+1:ro=row+1
colspan(row,col)=1:rowspan(row,col)=1 'default span = 1
WHILE colspanMk(row,co)
INC(colspan(row,col))
INC(co)
WEND
WHILE rowspanMk(ro,col)
INC(rowspan(row,col))
INC(ro)
WEND
NEXT
NEXT
'Step 3 -- Build HTML, open window, and put source into TE fld
k = FN GetNextWindow
LONG IF k
gWindows(k)=0 'mark id to be in use
CALL SETRECT(aRect,10,40,400,460) 'window rect
winTitle$ = fname$+".html" 'window title
WINDOW #-k,winTitle$,@aRect,_docZoom 'make a new window
TEXT gFont, gSize 'setup text font & size
EDIT FIELD #-k,"",(1,1)-(WINDOW(_width)-1,WINDOW(_height)-1),_noFramed
'styled TE (negative ID edit fld) required for scrollbar/cripboard support
SCROLL BUTTON #-k,1,1,1,1,,_scrollVert 'vertical scrollbar
WINDOW #k 'show window
tmp$="<TABLE BORDER="+STR$(gBorder)+" CELLPADDING="+STR$(gPadding)+">"+CHR$(13)
IF gIndent THEN tmp$=tmp$+SPACE$(2)
FN TEappend(k,tmp$) 'Put table tag into TE fld
LONG IF gCaption$<>""
tmp$="<CAPTION>"+gCaption$+"</CAPTION>"+CHR$(13)
FN TEappend(k,tmp$) 'Put caption tag if exists
END IF
row=0
WHILE NOT (EOF(1) OR row>_maxRow)
INC(row)
LINE INPUT #1, txt$ 'Read the first line
'If the first row of the text seems caption...
LONG IF row=1 AND gCaption$="" AND INSTR(1,txt$,CHR$(9))=0
tmp$="<CAPTION>"+txt$+"</CAPTION>"+CHR$(13)
IF gIndent THEN tmp$=tmp$+SPACE$(2)
FN TEappend(k,tmp$) 'Put caption tag into TE fld
LINE INPUT #1, txt$
INC(row)
END IF
tmp$="<TR>"
IF gIndent THEN tmp$=tmp$+CHR$(13)+SPACE$(4)
IF gComments THEN tmp$=gLine$+tmp$ 'Add devide line into TE fld
FN TEappend(k,tmp$):tmp$=""
col=1
FOR c=1 TO LEN(txt$)
c$=MID$(txt$,c,1)
LONG IF c$=CHR$(9) 'If we reached cell border
LONG IF NOT(tmp$="=" OR tmp$=""")
IF gColHeader AND col=1 OR gRowHeader THEN ctag$="TH" ELSE ctag$="TD"
LONG IF rowspan(row,col)>1
ctag$=ctag$+" ROWSPAN="+STR$(rowspan(row,col))
END IF
LONG IF colspan(row,col)>1
ctag$=ctag$+" COLSPAN="+STR$(colspan(row,col))
END IF
tmp$="<"+ctag$+">"+tmp$+"</"+LEFT$(ctag$,2)+">"
IF gIndent THEN tmp$=tmp$+CHR$(13)+SPACE$(2)
IF gIndent AND c<>LEN(txt$)-2*colspan(row,col)+3 THEN tmp$=tmp$+SPACE$(2)
FN TEappend(k,tmp$) 'Put a cell into TE fld
END IF
INC(col)
tmp$=""
XELSE 'If not cell border,
c$=FN NamedEntity$(c$) 'convert "&<> to named entitiy
tmp$=tmp$+c$ 'and accumulate chars
END IF
NEXT
'The last cell can't be found by tab, so here we handle the rest of line.
LONG IF NOT(tmp$="=" OR tmp$=""")
IF gRowHeader THEN ctag$="TH" ELSE ctag$="TD"
LONG IF rowspan(row,col)>1
ctag$=ctag$+" ROWSPAN="+STR$(rowspan(row,col))
END IF
tmp$="<"+ctag$+">"+tmp$+"</"+LEFT$(ctag$,2)+">"
IF gIndent THEN tmp$=tmp$+CHR$(13)+SPACE$(2)
FN TEappend(k,tmp$)
END IF
tmp$="</TR>"+CHR$(13)
IF gIndent AND row<>lastRow THEN tmp$=tmp$+SPACE$(2)
FN TEappend(k,tmp$)
gRowHeader=_false
WEND
CLOSE #1 'Done with text file
tmp$="</TABLE>
FN TEappend(k,tmp$) 'Put table closing tag
XELSE
msg$="Sorry, no more windows can be opened."
FN DoStopAlert(msg$)
END IF
END FN